package com.qinggeng.project.api.websocket.service;

import com.qinggeng.common.constant.HttpStatus;
import com.qinggeng.framework.config.mq.dto.MessageBulletChatDTO;
import com.qinggeng.framework.config.mq.dto.MessageRedEnvelopesDTO;
import com.qinggeng.project.api.websocket.AppWebSocketServer;
import com.qinggeng.project.api.websocket.enums.MessageModelEnum;
import com.qinggeng.project.api.websocket.vo.MessageBulletChatVO;
import com.qinggeng.project.system.domain.SysUser;
import com.qinggeng.project.system.service.ISysUserService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Component
public class BulletChatRedEnvelopesServiceImpl {

    @Resource
    private ISysUserService sysUserService;

    public  void  send( MessageRedEnvelopesDTO dto){
        Long userId= dto.getUserId();
        if (null == userId){
            return;
        }
        SysUser sysUser=sysUserService.selectUserById(userId);
        if (null !=sysUser){
            MessageBulletChatVO messageModel=new MessageBulletChatVO();
            messageModel.setCode(HttpStatus.SUCCESS);
            messageModel.setType(MessageModelEnum.RED_ENVE_LOPES.getValue());

            messageModel.setUserId(userId.toString());
            Map<String,String> data= new HashMap<>();
            String avatar=sysUser.getAvatar();
            String money= dto.getMoney();
            data.put("headImg",avatar);
            String nickName=sysUser.getNickName();
            StringBuilder stringBuilder=new StringBuilder();
            stringBuilder.append(nickName)
                    .append("抢到了")
                    .append(money)
                    .append("元红包");
            data.put("context",stringBuilder.toString());
            messageModel.setData(data);
            AppWebSocketServer.massHair(messageModel);
        }
    }
}
